const request=require("superagent");
const cheerio = require('cheerio');
const iconv = require('iconv-lite');
const util = require('util');
const charset = require("superagent-charset")(request);
const fs=require('fs');
var mysql      = require('mysql');
const assert = require('assert');
var connection = mysql.createConnection({
  host     : '127.0.0.1',
  user     : 'root',
  password : '123456',
  database : 'node'
});
connection.query = util.promisify(connection.query);


async function getList(){

	let sql=`select * from m_matter_a where area_id = 61`;
	let result=await connection.query(sql);
	let num = 0;
	for (var i = 0; i < result.length; i++) {
		console.log(result[i]["id"],result[i]["name"])
			let datafloder = await connection.query(`select * from test where name = '${result[i]["implement_code"]}'`);
			if(datafloder.length==0){
				num++;
				console.error(num,'未找到事项',result[i]["id"])
			}else{
				await connection.query(`update test SET status = 1 where id = '${datafloder[0]['id']}'`);
				await connection.query(`update m_matter_a SET event_status = 1 where id = '${result[i]["id"]}'`);
			}
		

	}



		
}

async function asySql(addSql,addSqlParams){
	return await new Promise(resolve => {
		connection.query(addSql,addSqlParams,function (err, result) {
	        if(err){
	         console.log('[INSERT ERROR] - ',err.message);
	         return;
	        }else{
	        	console.log('INSERT ID:',result.insertId);
		    	return resolve(result.insertId);
	        }        
	 		
		});
	})
		
}

getList();
